package com.example.zzzfragmenttest;





import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;


public class Main  extends Activity implements OnClickListener{
	

    protected void onCreate(Bundle savedInstanceState) {
    	
    	super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

		if (savedInstanceState == null) {
			// on first time display view for first nav item
			displayView(0);
		}
		
		Button b=(Button) this.findViewById(R.id.hidden);
		b.setOnClickListener(this);
		
    }//end onCreate
	
		private void displayView(int position) {
		// update the main content by replacing fragments
		Fragment fragment = null;
		switch (position) {
		case 0:
			fragment = new AAA();
			break;
		case 1:
			fragment = new BBB();
			break;
		default:
			break;
		}
		
		if (fragment != null) {
			FragmentManager fragmentManager = getFragmentManager();
			fragmentManager.beginTransaction()
					.replace(R.id.frame_container, fragment).commit();

		} else {
			// error in creating fragment
			Log.e("MainActivity", "Error in creating fragment");
		}
		}

		@Override
		public void onClick(View v) {
			displayView(1);
			
		}
		

}
